//package com.example.test;
//
//import com.aliyun.oss.OSS;
//import com.aliyun.oss.OSSClientBuilder;
//import com.aliyun.oss.OSSException;
//import com.aliyun.oss.internal.OSSHeaders;
//import com.aliyun.oss.model.*;
//import com.aliyuncs.exceptions.ClientException;
//import lombok.SneakyThrows;
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.InputStream;
//import java.util.Date;
//import java.util.concurrent.ThreadLocalRandom;
//
//public class ClientUpload {
//    @SneakyThrows
//    public static void main(String[] args) throws ClientException {
//// OSS访问域名。以华东1（杭州）地域为例，填写为https://oss-cn-hangzhou.aliyuncs.com。其它Region请按实际情况填写。
//        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
//// 从环境变量中获取步骤5生成的临时访问密钥AccessKey ID和AccessKey Secret，非阿里云账号AccessKey ID和AccessKey Secret。
//        String accessKeyId = "STS.NXMxrtoRAHcdPyYH2btv1BXiE";
//        String accessKeySecret = "9gttR98YfixeNwdi7qxxgh58gxJS7jbxPQ2eZoAmC8ZY";
//// 从环境变量中获取步骤5生成的安全令牌SecurityToken。
//        String securityToken = "CAIS/AN1q6Ft5B2yfSjIr5v4M8jAgo1g/6GPUl/orDI3ePkdrZ3Cpzz2IHhMdXJoBegXsfQ+m25S5v4alqx9SoVeWRRJ73uAXc4Fnzm6aq/t5uZMh95t0e9JcAr+Ihr/29CoLIedZdjBe/CrRknZnytou9XTfimjWFrXVv/sjoV8POwKQi6ybzdNGK1sRG1YpdQdKGHaONu0LxfumRCwNkdzvRdmgm4Nt8bPy8aHuB3Flw+4mK1Hv4ntOpytacRweYklMaW81/ckcbHagmwCqUpS+btuiKVC9CuCoIvaQSu9infrGu7Q9cIVY20dT6MmGqlCgeHhnPljwIL6nJj2zBA/WoMwVD/EFq+t3OzOGu6iKqwDF9DBNm/Kz8qEO7Tsrgogegh7Dg5RfMc7IXICV35cQzrBeKi84wKIMEXxU6WZyKU/15dpikuyn6iDLEPdRK6Cg2RKeM0kYl8wMxcQ0HCkbPVBMS40Kgs+XOrPHdspPUkG8fuz5je/DHMwkitl2NTlfO7Tt6wlboHyY4lLy4J1Zu4d6zN7FAyrE+Px2hZLKjY1Ge5Mu7HgJY9WLBIGezsdCASvKIfk2j0yGVi5x0IGGeFBpMlCyPeXyEtKiiXATZG9Yl5aan8KzPpxYy97n5gjAdJILQVcwepdXmGBNlLuyg4Snr98l+IvDmQ6Fp/MGoABIqsJx91M63c2KkCOA7n3TEW5z0CbMu4HOz5h5MUqwQH/B2tp0ZiONUyFBKpBdbldTajlwQq6eaUWWJD6XZYj4CMHJFqKVb94ytgQ0fv26zioNVctSuHy+EmarpDs9pdeAYUqxMteqSsN0ZChvE2afZwJ8+A4POTs11whhh2GOPEgAA==";
//        // 创建OSSClient实例。
//        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret, securityToken);
//// 将本地文件exampletest.txt上传至examplebucket。
//
//
//
//        String callbackUrl = "http://47.122.44.26:8083/content/callBack";
//
//
//        // 指定存储路径
//        String bucketName = "petplanet-v2";
//        Long userId = 6L; // 示例用户ID
//
//
//        // 获取当前时间戳（秒级）
//        long timestamp = System.currentTimeMillis() / 1000;
//        // 生成一个 6 位的随机数
//        long randomNum = ThreadLocalRandom.current().nextLong(100000, 999999);
//
//
////        String uploadId = timestamp + "_" + randomNum;
//
//
//
//        String uploadId = "1742465489_904721";
//
//        System.out.println("uploadId:"+uploadId);
//
//        String uploadFinalName = String.valueOf(randomNum);
//
//        String finalName = "image/" + userId + "/" + uploadId + "/"+uploadFinalName+".jpg"; // 构造对象名
//
//        System.out.println("finalName:"+finalName);
//
//        InputStream inputStream = new FileInputStream("C:\\Users\\L\\Desktop\\004.jpg");
//        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, finalName,inputStream);
////         ObjectMetadata metadata = new ObjectMetadata();
//        // 上传文件时设置存储类型。
////        metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.Standard.toString());
//// 上传文件时设置读写权限ACL。
//// metadata.setObjectAcl(CannedAccessControlList.Private);
//// putObjectRequest.setMetadata(metadata);
//
//            // 上传回调参数。
//            Callback callback = new Callback();
//            callback.setCallbackUrl(callbackUrl);
//            //（可选）设置回调请求消息头中Host的值，即您的服务器配置Host的值。
//            // callback.setCallbackHost("yourCallbackHost");
//            //设置发起回调请求的自定义参数，由Key和Value组成，Key必须以x:开始。
//            callback.addCallbackVar("x:userId",userId.toString());
//            callback.addCallbackVar("x:uploadId",uploadId);
//            // 设置发起回调时请求body的值。
//            callback.setCallbackBody("{\\\"bucket\\\":${bucket},\\\"object\\\":${object},\\\"size\\\":${size},\\\"etag\\\":${etag},\\\"userId\\\":${x:userId},\\\"uploadId\\\":${x:uploadId},\\\"clientIp\\\":${x:clientIp}}");
////            callback.setCallbackBody("{\\\"mimeType\\\":${mimeType},\\\"size\\\":${size}}");
//            // 设置发起回调请求的Content-Type。
//            callback.setCalbackBodyType(Callback.CalbackBodyType.JSON);
//
//            putObjectRequest.setCallback(callback);
//
//
//        try {
//            // 上传文件。
//            PutObjectResult putObjectResult = ossClient.putObject(putObjectRequest);
//
//        } catch (OSSException oe) {
//            System.out.println("Caught an OSSException, which means your request made it to OSS, "
//                    + "but was rejected with an error response for some reason.");
//            System.out.println("Error Message:" + oe.getErrorMessage());
//            System.out.println("Error Code:" + oe.getErrorCode());
//            System.out.println("Request ID:" + oe.getRequestId());
//            System.out.println("Host ID:" + oe.getHostId());
//        } finally {
//            if (ossClient != null) {
//                ossClient.shutdown();
//            }
//        }
//    }
//}